class Basics {
static int x=1;
void m(int i) {x++;i++;}
public static void main (String[] args) {
int y=3;
m(y);
System.out.println(x + "," + y);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1,3 |
| b. | Prints: 2,3 |
| c. | Prints: 1,3 |
| d. | Prints: 2,4 |
| e. | Run time Exception |
| f. | Compiler Error |
| g. | None of the Above |
class A {
static boolean a;
static boolean b;
static boolean c;
public static void main (String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Runtime error |
| j. | Compiler error |
| k. | None of the above |
class X {
public static void main(String args[]) {
double a = 1.0f / 3.0f;
double b = 1.0d / 3.0f;
double c = 1.0d / 3.0d;
System.out.print((a==b) + ",");
System.out.print((a==c) + ",");
System.out.print(b==c);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Runtime error |
| j. | Compiler error |
| k. | None of the above |
class A {
static boolean a;
static boolean b;
static boolean c;
public static void main (String[] args) {
boolean x = a || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Runtime error |
| j. | Compiler error |
| k. | None of the above |
class A {
public static void main (String[] args) {
int a = 1 || 2 ^ 3 && 5;
int b = ((1 || 2) ^ 3) && 5;
int c = 1 || (2 ^ (3 && 5));
System.out.print(a + "," + b + "," + c);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 0,0,0 |
| b. | Prints: 0,0,3 |
| c. | Prints: 0,3,0 |
| d. | Prints: 0,3,3 |
| e. | Prints: 3,0,0 |
| f. | Prints: 3,0,3 |
| g. | Prints: 3,3,0 |
| h. | Prints: 3,3,3 |
| i. | Runtime error |
| j. | Compiler error |
| k. | None of the above |
class L {
public static void main (String s[]) {
int i = 1 | 2 ^ 3 * 2 & 13 | 2;
System.out.println(i%5);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1 |
| b. | Prints: 2 |
| c. | Prints: 3 |
| d. | Prints: 4 |
| e. | Prints: 5 |
| f. | Runtime error |
| g. | Compiler error |
| h. | None of the above |
class Basics {
private static int x=1;
static void m(int i) {x++;i++;}
public static void main (String[] args) {
int y=3;
m(y);
System.out.println(x + "," + y);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1,3 |
| b. | Prints: 2,3 |
| c. | Prints: 1,3 |
| d. | Prints: 2,4 |
| e. | Run time Exception |
| f. | Compiler Error |
| g. | None of the Above |
class UltraViolet {
public static void main (String[] args) {
char a = '\u002a'; // Asterisk
char b = '\u0024'; // Dollar Sign
System.out.print(a + b);
System.out.print(" ABC" + a + b);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 78 ABC*$ |
| b. | Prints: *$ ABC*$ |
| c. | Prints: 78 ABC78 |
| d. | Compiler error. |
| e. | Runtime error. |
| f. | None of the Above |
1. interface I1 {}
2. interface I2 {}
3. class Base implements I1 {}
4. class Sub extends Base implements I2 {}
5. class Gray {
6. public static void main(String []args) {
7. Base[] base = {new Base()};
8. Sub sub[] = {new Sub()};
9. Object obj = sub;
10. base = obj;
11. }
12. }
What is the result of attempting to compile and run the above program?
| a. | Compiler error at line 7. |
| b. | Runtime error at line 7. |
| c. | Compiler error at line 8. |
| d. | Runtime error at line 8. |
| e. | Compiler error at line 9. |
| f. | Runtime error at line 9. |
| g. | Compiler error at line 10. |
| h. | Runtime error at line 10. |
| i. | Compiles and runs without error. |
class Red {
public static void main (String[] args) {
byte a = 1, b = 2, c, d, e;
c = (byte)a++;
d = (byte)++b;
e = (byte)a + b;
System.out.print(c + d + e);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1 2 3 |
| b. | Prints: 6 |
| c. | Prints: 2 3 5 |
| d. | Prints: 10 |
| e. | Prints: 1 3 4 |
| f. | Prints: 8 |
| g. | Prints: 1 3 5 |
| h. | Prints: 9 |
| i. | Runtime error. |
| j. | Compiler error. |
| k. | None of the Above |
class M {
static int m(int i) {
System.out.print(i + ", ");
return i;
}
public static void main(String s[]) {
int i=0;
int j = m(++i) + m(++i) * m(++i) % m(++i) + m(++i);
System.out.print(j%5);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1,2,3,4,5,1 |
| b. | Prints: 1,2,3,4,5,2 |
| c. | Prints: 1,2,3,4,5,3 |
| d. | Prints: 1,2,3,4,5,4 |
| e. | Prints: 1,2,3,4,5,5 |
| f. | Runtime error |
| g. | Compiler error |
| h. | None of the above |
1. class Purple {
2. public static void main (String []args) {
3. int[] i = {1,2,3};
4. Object obj = i;
5. i = obj;
6. }
7. }
What is the result of attempting to compile and run the above program?
| a. | Compiler error at line 2. |
| b. | Runtime error at line 2. |
| c. | Compiler error at line 3. |
| d. | Runtime error at line 3. |
| e. | Compiler error at line 4. |
| f. | Runtime error at line 4. |
| g. | Compiler error at line 5. |
| h. | Runtime error at line 5. |
| i. | Compiles and runs without error. |
class A {}
class B extends A {}
class C extends B {
static void m(A x, A y) {System.out.print("AA");}
static void m(A x, B y) {System.out.print("AB");}
static void m(B x, A y) {System.out.print("BA");}
static void m(B x, B y) {System.out.print("BB");}
public static void main(String[] args) {
A a;
B b;
m(null,null);
m(a=null,b=null);
m(b, a);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: BBABAB |
| b. | Prints: BBABBA |
| c. | Prints: BBBBAB |
| d. | Prints: BBBBBA |
| e. | Prints: BBBBBB |
| f. | Compiler error. |
| g. | Runtime error. |
| h. | None of the Above |
class S {
public static void main(String args[]) {
byte b = -1,c,d; // 1
c = (byte)(b >>> 1); // 2
d = (byte)(b >>> 25); // 3
System.out.print(c+","+d);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 127,0 |
| b. | Prints: 0,127 |
| c. | Prints: -1,0 |
| d. | Prints: -1,127 |
| e. | Prints: -1,-1 |
| f. | Prints: 127,127 |
| g. | Runtime error |
| h. | Compiler error |
| i. | None of the above |
import java.io.Serializable;
1. class Blue {
2. public static void main (String args[]) {
3. int[] i = {1,2,3};
4. Serializable s = i;
5. i = (int [])s;
6. }
7. }
What is the result of attempting to compile and run the above program?
| a. | Compiler error at line 3. |
| b. | Runtime error at line 3. |
| c. | Compiler error at line 4. |
| d. | Runtime error at line 4. |
| e. | Compiler error at line 5. |
| f. | Runtime error at line 5. |
| g. | Compiles and runs without error. |
1. interface I1 {}
2. interface I2 {}
3. class Base implements I1 {}
4. class Sub extends Base implements I2 {}
5.
6. class Red {
7. public static void main(String args[]) {
8. Sub s1 = new Sub();
9. I2 i2 = s1;
10. I1 i1 = s1;
11. Base base = s1;
12. Sub s2 = (Sub)base;
13. }
14. }
What is the result of attempting to compile and run the above program?
| a. | Compiler error at line 9. |
| b. | Compiler error at line 10. |
| c. | Compiler error at line 11. |
| d. | Compiler error at line 12. |
| e. | Runtime error. |
| f. | Compiles and runs without error. |
class L {
static String m(float i) {return "float";}
static String m(double i) {return "double";}
public static void main (String[] args) {
int a = 1;
long b = 2;
System.out.print(m(a)+","+ m(b));
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: float,float |
| b. | Prints: float,double |
| c. | Prints: double,float |
| d. | Prints: double,double |
| e. | Compiler error. |
| f. | Runtime error. |
| g. | None of the Above |
class Blue {
public static void main (String[] args) {
byte b1 = (byte)(2 * Byte.MAX_VALUE);
byte b2 = -1;
byte b3 = -2;
byte b4 = -3;
System.out.println((b1==b2)+","+(b1==b3)+","+(b1==b4));
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: true,false,false |
| e. | Compiler error. |
| f. | Runtime error. |
| g. | None of the Above |